package com.hcss.core.util;

import javax.servlet.http.HttpServletRequest;

/** 
 * @ClassName: CommonUtil 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author lvfang
 * @date 2013-12-10 上午9:26:52 
 *  
 */
public class CommonUtil {
	/** 
	* <p> getRemortAddr TODO获取IP地址</p>
	* @param request
	* @return  String 设定文件 
	*/
	public static String getRemortAddr(HttpServletRequest request){
		String ip = request.getHeader("x-forwarded-for");
       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
           ip = request.getHeader("Proxy-Client-IP");
       }
       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
           ip = request.getHeader("WL-Proxy-Client-IP");
       }
       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
           ip = request.getRemoteAddr();
       }
       if("0:0:0:0:0:0:0:1".equals(ip)){
    	   ip = "127.0.0.1";
       }
       return ip;
	}
	
	/** 
	* <p> sqlReplace TODO  替换SQL中 select 的大小写</p>
	* @param sql
	* @return  String 设定文件 
	*/
	public static String sqlReplace(String sql){
		if(StringUtils.isNotEmpty(sql)){
			return sql.substring(0,6).toLowerCase()+" "+sql.substring(7);
		}
		return sql;
	}
}
